﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HairFacebookApp.DTO;
using HairFacebookApp.DAO.Util;
using System.IO;

namespace HairFacebookApp.DAO
{
    public class CsvDao
    {
        //Quay so LuckyString
        private String luckyStr = "";
        //Data file path              
        private String covChar = "<br/>";
        //Variable for csvReaderFile
        private CsvFileReader csvReaderQuestionFile;

        // Variable for read from database - question
        private int iRowMin;
        private int iRowMax;
        private int iQuesColumn;
        private int iAnsColumn;

        // Variable for write to database - user information        
        private static int iColumnMin = 1;

        //Constructor
        public CsvDao()
        {
            //Get csv Question file
            String questionFile = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("App_Data"), "question.csv");
            csvReaderQuestionFile = new CsvFileReader(questionFile);
            //Set up luckyString
            int i = 0;
            for (; i < 50; i++)
            {
                if (i == 10 || i == 40 || i == 21 || i == 35 || i == 1 || i == 49 || i == 33)
                    luckyStr += '1';
                else
                    luckyStr += '0';
            }
        }

        //Get first question
        public QuestionDto getFirstQuestion()
        {
            QuestionDto quesDto = new QuestionDto();
            //Read question 1                
            quesDto.Question = csvReaderQuestionFile.ReadCell(2, 1);
            int i = 2;// min row of question database file 
            iRowMax = 22;// max row of question database file
            for (; i <= iRowMax; i++)
            {
                string ansStr = csvReaderQuestionFile.ReadCell(i, 3);
                if (!String.IsNullOrEmpty(ansStr))
                {
                    quesDto.Answers.Add(ansStr);
                }
            }
            //
            return quesDto;
        }

        // Qestion database
        public void mapQuestionDatabase(int ques, char answerQues1)
        {
            switch (ques)
            {
                case 5:
                    iRowMin = 2;
                    iRowMax = 20;

                    iQuesColumn = 14;
                    iAnsColumn = 16;
                    break;
                case 2:
                    if (answerQues1 == 'A' || answerQues1 == 'a')
                    {
                        iRowMin = 2;
                        iRowMax = 7;
                    }
                    else if (answerQues1 == 'B' || answerQues1 == 'b')
                    {
                        iRowMin = 8;
                        iRowMax = 13;
                    }
                    else if (answerQues1 == 'C' || answerQues1 == 'c')
                    {
                        iRowMin = 14;
                        iRowMax = 19;
                    }
                    else if (answerQues1 == 'D' || answerQues1 == 'd')
                    {
                        iRowMin = 20;
                        iRowMax = 22;
                    }
                    iQuesColumn = 5;
                    iAnsColumn = 7;
                    break;
                case 3:
                    if (answerQues1 == 'A' || answerQues1 == 'a')
                    {
                        iRowMin = 2;
                        iRowMax = 7;
                    }
                    else if (answerQues1 == 'B' || answerQues1 == 'b')
                    {
                        iRowMin = 8;
                        iRowMax = 13;
                    }
                    else if (answerQues1 == 'C' || answerQues1 == 'c')
                    {
                        iRowMin = 14;
                        iRowMax = 19;
                    }
                    else if (answerQues1 == 'D' || answerQues1 == 'd')
                    {
                        iRowMin = 20;
                        iRowMax = 22;
                    }
                    iQuesColumn = 8;
                    iAnsColumn = 10;
                    break;
                case 4:
                    if (answerQues1 == 'A' || answerQues1 == 'a')
                    {
                        iRowMin = 2;
                        iRowMax = 7;
                    }
                    else if (answerQues1 == 'B' || answerQues1 == 'b')
                    {
                        iRowMin = 8;
                        iRowMax = 13;
                    }
                    else if (answerQues1 == 'C' || answerQues1 == 'c')
                    {
                        iRowMin = 14;
                        iRowMax = 19;
                    }
                    else if (answerQues1 == 'D' || answerQues1 == 'd')
                    {
                        iRowMin = 20;
                        iRowMax = 22;
                    }
                    iQuesColumn = 11;
                    iAnsColumn = 13;
                    break;
            }
        }

        // Get question:
        //@param: int Ques
        //@ question 1 answer
        public QuestionDto getNextQuestion(int iQues, char answerQues1)
        {
            QuestionDto qDto = new QuestionDto();
            try
            {
                //Mapping question location
                mapQuestionDatabase(iQues, answerQues1);
                //Get question
                qDto.Question = csvReaderQuestionFile.ReadCell(2, iQuesColumn);
                int i = iRowMin;
                for (; i <= iRowMax; i++)
                {
                    String ansStr = csvReaderQuestionFile.ReadCell(i, iAnsColumn);
                    if (!String.IsNullOrEmpty(ansStr))
                        qDto.Answers.Add(ansStr);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            //
            return qDto;
        }

        //Save user information
        //@param: userDto userDto               
        public Boolean saveUserInfo(UserDto userInfo)
        {
            try
            {
                String userInfoFile = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("App_Data"), "userInfo.csv");
                using (CsvFileWriter writer = new CsvFileWriter(userInfoFile, System.Text.Encoding.UTF8))
                {
                    //Write userDto to CSV file  
                    //User Info
                    CsvRow row = new CsvRow();
                    row.Add(userInfo.Name);
                    row.Add(userInfo.Birthday);
                    row.Add(userInfo.Place);
                    row.Add(userInfo.Image);

                    //User's answer: A,B,C,D. Ques 1 -> Ques 4                                  
                    int j = 0;
                    for (; j < userInfo.UserAnsweredQues.Count - 1; j++)
                        row.Add(userInfo.UserAnsweredQues[j].getUserAnswerKey().ToString());
                    //The fifth question
                    row.Add(userInfo.UserAnsweredQues[userInfo.UserAnsweredQues.Count - 1].No5Answer);
                    //Result
                    row.Add(userInfo.Result);
                    //Date
                    row.Add(userInfo.Date);
                    //Save to File
                    writer.WriteRow(row);
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return true;
        }

        //Read result file
        public String readResult(int row, int col, String fileName)
        {
            String res = "";
            String resFile = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("App_Data"), fileName);
            try
            {
                //Open database file
                CsvFileReader csvReader = new CsvFileReader(resFile);
                String resStr = csvReader.ReadCell(row, col);
                if (!String.IsNullOrEmpty(resStr))
                    res = resStr;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return res;
        }

        //Get user answer key (user for 5th question)
        public Boolean findAnswerKey(QuestionDto quesDto, Char key)
        {
            int i = 0;
            for (; i < quesDto.No5AnswerKey.Length; i++)
                if (quesDto.No5AnswerKey[i] == key)
                    return true;
            return false;
        }

        //Get user result
        //@param: userDto userDto 
        public Boolean getUserResult(UserDto userInfo)
        {
            try
            {
                //Base on question 1 answer
                char ques1Ans = userInfo.UserAnsweredQues[0].getUserAnswerKey();
                switch (ques1Ans)
                {
                    case 'A':
                        //KL
                        userInfo.Result += readResult(2, 6, "result1A.csv");
                        userInfo.Result += covChar;
                        //KL4
                        if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(9, 9, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(10, 9, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(11, 9, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(12, 9, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'E')
                        {
                            userInfo.Result += readResult(13, 9, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        //KL2
                        if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'A'
                            || userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'B'
                            || userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(2, 7, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(3, 7, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'E')
                        {
                            userInfo.Result += readResult(4, 7, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        //KL3
                        if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(5, 8, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(6, 8, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(7, 8, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(8, 8, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        //KL5
                        if (findAnswerKey(userInfo.UserAnsweredQues[4], 'C') || findAnswerKey(userInfo.UserAnsweredQues[4], 'D'))
                        {
                            userInfo.Result += readResult(16, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'B'))
                        {
                            userInfo.Result += readResult(15, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'A'))
                        {
                            userInfo.Result += readResult(14, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }                                                
                        //Loi Khuyen
                        userInfo.Result += readResult(2, 11, "result1A.csv");
                        userInfo.Result += ".";
                        break;
                    case 'B':
                        //KL
                        userInfo.Result += readResult(2, 6, "result1B.csv");
                        userInfo.Result += covChar;
                        //KL4
                        if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(9, 9, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(10, 9, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(11, 9, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(12, 9, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'E')
                        {
                            userInfo.Result += readResult(13, 9, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        //KL2
                        if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'A' || userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'B' || userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(2, 7, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(3, 7, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'E')
                        {
                            userInfo.Result += readResult(4, 7, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        //KL3
                        if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(5, 8, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(6, 8, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(7, 8, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(8, 8, "result1B.csv");
                            userInfo.Result += covChar;
                        }
                        //KL5
                        if (findAnswerKey(userInfo.UserAnsweredQues[4], 'C') || findAnswerKey(userInfo.UserAnsweredQues[4], 'D'))
                        {
                            userInfo.Result += readResult(16, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'B'))
                        {
                            userInfo.Result += readResult(15, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'A'))
                        {
                            userInfo.Result += readResult(14, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }                             
                        //Loi Khuyen
                        userInfo.Result += readResult(2, 11, "result1B.csv");
                        userInfo.Result += ".";
                        break;
                    case 'C':
                        //KL
                        userInfo.Result += readResult(2, 6, "result1C.csv");
                        userInfo.Result += covChar;
                        //KL4
                        if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(9, 9, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(10, 9, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(11, 9, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(12, 9, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        //KL2
                        if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'A' || userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(2, 7, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'C' || userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'E')
                        {
                            userInfo.Result += readResult(3, 7, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(4, 7, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        //KL3
                        if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'A' || userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'E')
                        {
                            userInfo.Result += readResult(5, 8, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(7, 8, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(6, 8, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'D')
                        {
                            userInfo.Result += readResult(8, 8, "result1C.csv");
                            userInfo.Result += covChar;
                        }
                        //KL5
                        if (findAnswerKey(userInfo.UserAnsweredQues[4], 'C') || findAnswerKey(userInfo.UserAnsweredQues[4], 'D'))
                        {
                            userInfo.Result += readResult(16, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'B'))
                        {
                            userInfo.Result += readResult(15, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'A'))
                        {
                            userInfo.Result += readResult(14, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }       
                        //Loi Khuyen
                        userInfo.Result += readResult(2, 11, "result1C.csv");
                        userInfo.Result += ".";
                        break;
                    case 'D':
                        //KL
                        userInfo.Result += readResult(2, 6, "result1D.csv");
                        userInfo.Result += covChar;
                        //KL4
                        if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(9, 9, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(10, 9, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[3].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(11, 9, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        //KL2
                        if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(2, 7, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[1].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(3, 7, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        //KL3
                        if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'A')
                        {
                            userInfo.Result += readResult(5, 8, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'B')
                        {
                            userInfo.Result += readResult(6, 8, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        else if (userInfo.UserAnsweredQues[2].getUserAnswerKey() == 'C')
                        {
                            userInfo.Result += readResult(7, 8, "result1D.csv");
                            userInfo.Result += covChar;
                        }
                        //KL5
                        if (findAnswerKey(userInfo.UserAnsweredQues[4], 'C') || findAnswerKey(userInfo.UserAnsweredQues[4], 'D'))
                        {
                            userInfo.Result += readResult(16, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'B'))
                        {
                            userInfo.Result += readResult(15, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }
                        else if (findAnswerKey(userInfo.UserAnsweredQues[4], 'A'))
                        {
                            userInfo.Result += readResult(14, 10, "result1A.csv");
                            userInfo.Result += covChar;
                        }       
                        //Loi Khuyen
                        userInfo.Result += readResult(2, 11, "result1D.csv");
                        userInfo.Result += ".";
                        break;
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return true;
        }

        //Check user Quay so status
        //@param: String userFBID
        public Boolean checkUserQuaySoStatus(String userFBID)
        {
            try
            {
                //Get csv QuaysoInfo file
                String quaySoInfoFile = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("App_Data"), "quaySoInfo.csv");
                CsvFileReader csvReaderquaySoInfoFile = new CsvFileReader(quaySoInfoFile);
                //Read userInfo file to check status                
                int i = 2;//Not count the topic
                for (; i <= csvReaderquaySoInfoFile.Data.Count; i++)
                {
                    //Find FB ID
                    String strFBID = csvReaderquaySoInfoFile.ReadCell(i, 2);
                    if (String.Compare(strFBID, userFBID) == 0 && String.Compare(strFBID, "") != 0)
                    {
                        //Get quay so status
                        String strQuaySoStatus = csvReaderquaySoInfoFile.ReadCell(i, 7);
                        if (strQuaySoStatus.ToCharArray()[0] == '1')
                            return true;
                    }
                    csvReaderquaySoInfoFile.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            //Khong tim thay user fbID
            return false;
        }

        //Check user Quay so status
        //@param: String userFBID
        public int checkAwardPeopleNumber()
        {
            int result = 0;
            try
            {
                //Get csv QuaysoInfo file
                String quaySoInfoFile = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("App_Data"), "quaySoInfo.csv");
                CsvFileReader csvReaderquaySoInfoFile = new CsvFileReader(quaySoInfoFile);
                //Read userInfo file to check people number in today
                String strToday = DateTime.Today.ToString("d");
                int i = 2;//Not count the topic
                for (; i <= csvReaderquaySoInfoFile.Data.Count; i++)
                {
                    //Find Date
                    String strDate = csvReaderquaySoInfoFile.ReadCell(i, 8);
                    if (String.Compare(strToday, strDate) == 0)
                        result++;
                }
                csvReaderquaySoInfoFile.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            //Khong tim thay user fbID
            return result;
        }

        //Save user information to QuaySo
        //@param: userDto userDto               
        public Boolean saveQuaySoInfo(QuaySoDto quaySoInfo)
        {
            try
            {
                String quaySoInfoFile = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("App_Data"), "quaySoInfo.csv");
                using (CsvFileWriter writer = new CsvFileWriter(quaySoInfoFile, System.Text.Encoding.UTF8))
                {
                    //Write userDto to CSV file  
                    //User Info
                    CsvRow row = new CsvRow();
                    row.Add(quaySoInfo.Name);
                    row.Add(quaySoInfo.FacebookID);
                    row.Add(quaySoInfo.Address);
                    row.Add(quaySoInfo.Phone);
                    row.Add(quaySoInfo.Email);
                    row.Add(quaySoInfo.Result);
                    row.Add(quaySoInfo.Quayso.ToString());
                    row.Add(quaySoInfo.Date);
                    //Save to File
                    writer.WriteRow(row);
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return true;
        }
        //Check user Quay so status
        //@param: String userFBID
        public Boolean randomQuaySo()
        {
            //Random present user number
            Random rRandom = new Random();
            int iNum = rRandom.Next(0, 49);
            //Search present user number
            if (luckyStr[iNum] == '1')
            {
                //Check if today have 2 people had recievied award   
                if (checkAwardPeopleNumber() < 1)
                    return true;//Trung thuong
            }
            //Ko trung thuong
            return false;
        }
    }
}